%% demo with SVM-CK with AVIRIS Indiana Pines dataset
%% for the composite kernel paper
%
%%
% [2] G. Camps-Valls, L. Gomez-Chova, J. Muoz-Mar, J. Vila-Francs, and J. Calpe-Maravilla, 
% “Composite kernels for hyperspectral image classi?cation,” 
% IEEE Geosci. Remote Sens. Lett., vol. 3, no. 1, pp. 93–97, Jan. 2006
%
%%
% If you use this demo, please be aware of the parameters involved in the
% building of the kernel functions and in the SVM algorithm, which might
% affect the final performance the CK framework. 
%
%%
% It is recommended to use other spatial features for evaluation
%
%%
% For any question and suggestion, it is greatly appreciated to contact the
% authors: jun@lx.it.pt
%

close all
clear all
clc

load EMP_Indina_profiles325 % EMP data
load imgreal; % original data
sz = size(img);
img = reshape(img, [prod(sz(1:2)) sz(3)]);   
img = img';
img([104:108 150:163 220],:) =[]; % remove noise bands
img= reshape(img',[145 145 200]);

no_classes=16;

% load ground truth data
load AVIRIS_Indiana_16class
trainall = trainall';


indexes=train_test_random_new(trainall(2,:),10,160);
train1 = trainall(:,indexes);  % training sample
test1=trainall;                % remaining samples are used for test
test1(:,indexes)=[];
        
train_img=zeros(145,145);          % training image
train_img(train1(1,:))=train1(2,:);

   
in_param.nfold = 5;  % cross validation for parameters
[outdata_w, out_param] = classify_svm_mykernel(img,EMP_KPCA_Indian,train_img,in_param);

[overall,kappa,average,classindividual] = calcError(test1(2,:)-1,outdata_w(test1(1,:))'-1,[1:no_classes]);
overall
